<?php

namespace app\common\model;

use app\common\basic\BaseModel;
use app\common\basic\BaseNormalModel;

class MessageNotification extends BaseNormalModel
{
    protected $table = 'vk_message_notifications';


    public function searchTitleAttr($query, $value)
    {
        $query->where('title', 'like', "%{$value}%");
    }

    public function type()
    {
        return $this->belongsTo(MessageNotificationType::class, 'type_id', 'id');
    }
    
    public function reads()
    {
        return $this->hasMany(MessageNotificationRead::class, 'message_notification_id', 'id');
    }

    public function company()
    {
        return $this->belongsToMany(Company::class, MessageNotificationCompany::class, 'company_id', 'notification_id');
    }
}